package com.yunji.base.convert;

import com.yunji.base.bo.GetSiteInfoBO;
import com.yunji.base.cache.BaseCache;
import com.yunji.base.domain.BelongDO;
import com.yunji.base.vo.SiteInfoVO;
import com.yunji.common.model.domain.SiteDO;
import com.yunji.common.utils.bean.BeanUtils;

/**
 * @author : peter-zhu
 * @date : 2024/12/13 10:27
 * @description : TODO
 **/
public class SiteConvert {

    public static GetSiteInfoBO getSiteAmountBO(Long siteId) {
        return getSiteInfoBO(BaseCache.getSite(siteId));
    }

    public static GetSiteInfoBO getSiteInfoBO(SiteDO site) {
        GetSiteInfoBO bo = new GetSiteInfoBO(site);
        BelongDO belong = BaseCache.getBelong(site.getBelongId());
        bo.setBelong(belong);
        Long agentId = belong.getAgentId();
        bo.setAgentId(agentId);
        bo.setAgentName(BaseCache.getAgentName(agentId));
        return bo;
    }


    public static SiteInfoVO getSiteInfoVo(GetSiteInfoBO siteAmountBO) {
        SiteInfoVO vo = new SiteInfoVO();
        BeanUtils.clone(siteAmountBO.getSite(), vo);
        BeanUtils.clone(siteAmountBO.getBelong(), vo);
        vo.setAgentId(siteAmountBO.getAgentId());
        vo.setAgentName(siteAmountBO.getAgentName());
        vo.setScale(siteAmountBO.getBelong().getScaleRatio());
        return vo;
    }
}
